//
//  CHAccountViewController.m
//  CarFile
//
//  Created by 陈浩 on 2017/7/30.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHAccountViewController.h"
#import "CHLoginViewController.h"
#import "CHHomeViewController.h"
#import "CHChangePwdController.h"
#import "CHNavigationController.h"
@interface CHAccountViewController ()

@end

@implementation CHAccountViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"账户中心";
    self.view.backgroundColor = KRGB(239, 239, 249);
    
    [self setupUI];
    
}

-(void)setupUI{
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, UIScreenW, 132)];
    bgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgView];
    
    UILabel *zhmcLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    zhmcLabel.text = @"账户名称:";
    zhmcLabel.textAlignment = NSTextAlignmentCenter;
    zhmcLabel.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:zhmcLabel];
    
    UILabel *usernameLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, UIScreenW - 100, 44)];
    usernameLabel.font =  [UIFont fontWithName:@"Helvetica-Bold" size:15];
    usernameLabel.text = [Globle getInstance].userInfoDic[@"userflag"];
    [bgView addSubview:usernameLabel];
    
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 44, UIScreenW, 1)];
    line.backgroundColor = [UIColor colorWithHexString:@"999999" alpha:0.3];
    [bgView addSubview:line];
    
    UILabel *glquLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 44, 100, 44)];
    glquLabel.text = @"管理区域:";
    glquLabel.textAlignment = NSTextAlignmentCenter;
    glquLabel.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:glquLabel];
    
    UILabel *manageLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 44, UIScreenW - 100, 44)];
    manageLabel.font =  [UIFont fontWithName:@"Helvetica-Bold" size:15];
    manageLabel.text = [Globle getInstance].userInfoDic[@"areacn"];
    [bgView addSubview:manageLabel];
    
    
    UIView *line1 = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(glquLabel.frame), UIScreenW, 1)];
    line1.backgroundColor = [UIColor colorWithHexString:@"999999" alpha:0.3];
    [bgView addSubview:line1];
    
    UILabel *xgmmLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(line1.frame), UIScreenW, 44)];
    xgmmLabel.text = @"修改密码";
    xgmmLabel.userInteractionEnabled = YES;
    xgmmLabel.textAlignment = NSTextAlignmentCenter;
    xgmmLabel.font = [UIFont systemFontOfSize:14];
    [bgView addSubview:xgmmLabel];
   
   UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(changePwd)];
   [xgmmLabel addGestureRecognizer:tap];
    
    
    UIButton *exitBtn = [[UIButton alloc] initWithFrame:CGRectMake(20, UIScreenH - 40 - 20 - 64, UIScreenW - 40, 40)];
    exitBtn.layer.cornerRadius = 5;
    exitBtn.layer.masksToBounds = YES;
    exitBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [exitBtn setTitle:@"退出账号" forState:UIControlStateNormal];
    [exitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [exitBtn setBackgroundImage:[UIImage imageNamed:@"search"] forState:UIControlStateNormal];
    [exitBtn addTarget:self action:@selector(exit) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:exitBtn];
    
    
}


-(void)exit{
    
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"你是否要退出？" preferredStyle:UIAlertControllerStyleAlert];
    [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        

        
    }]];
    [alert addAction:[UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [Util setBool:NO key:@"islogin"];
        
        CHLoginViewController *loginVc = [[CHLoginViewController alloc] init];
        CHNavigationController *nav = [[CHNavigationController alloc] initWithRootViewController:loginVc];
         UIWindow *window = [UIApplication sharedApplication].keyWindow;
        window.rootViewController = nav;
    
        
    }]];
    [self presentViewController:alert animated:YES completion:nil];
    
    
}


-(void)changePwd{
    
    id obj = [LongriseRouter openURL:@"CHChangePwdController"];
    if(obj && [obj isKindOfClass:[UIViewController class]])
    {
        UIViewController *vc = obj;
        [self.navigationController pushViewController:vc animated:YES];
    }

    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
